home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / ham / sattrk31.tgz / sattrack-3.1.tar / SatTrack / src / sattrack / satmath.c < prev    next >
C/C++ Source or Header  |  1995-03-16  |  4KB  |  81 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*  Title       : satmath.c                                                   */
  4. /*  Author      : Manfred Bester                                              */
  5. /*  Date        : 13Dec94                                                     */
  6. /*  Last change : 15Mar95                                                     */
  7. /*                                                                            */
  8. /*  Synopsis    : Auxiliary math routines for the satellite tracking program  */
  9. /*                SatTrack.                                                   */
  10. /*                                                                            */
  11. /*                                                                            */
  12. /*  SatTrack is Copyright (c) 1992, 1993, 1994, 1995 by Manfred Bester.       */
  13. /*  All Rights Reserved.                                                      */
  14. /*                                                                            */
  15. /*  Permission to use, copy, and distribute SatTrack and its documentation    */
  16. /*  in its entirety for educational, research and non-profit purposes,        */
  17. /*  without fee, and without a written agreement is hereby granted, provided  */
  18. /*  that the above copyright notice and the following three paragraphs appear */
  19. /*  in all copies. SatTrack may be modified for personal purposes, but        */
  20. /*  modified versions may NOT be distributed without prior consent of the     */
  21. /*  author.                                                                   */
  22. /*                                                                            */
  23. /*  Permission to incorporate this software into commercial products may be   */
  24. /*  obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,    */
  25. /*  Berkeley, CA 94709, USA. Note that distributing SatTrack 'bundled' in     */
  26. /*  with ANY product is considered to be a 'commercial purpose'.              */
  27. /*                                                                            */
  28. /*  IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, */
  29. /*  SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF   */
  30. /*  THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED  */
  31. /*  OF THE POSSIBILITY OF SUCH DAMAGE.                                        */
  32. /*                                                                            */
  33. /*  THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT      */
  34. /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A   */
  35. /*  PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"      */
  36. /*  BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, */
  37. /*  UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                  */
  38. /*                                                                            */
  39. /******************************************************************************/
  40.  
  41. #include <stdio.h>
  42. #include <math.h>
  43.  
  44. #ifndef STDLIB
  45. #include <stdlib.h>
  46. #endif
  47.  
  48. #include "sattrack.h"
  49.  
  50. /******************************************************************************/
  51. /*                                                                            */
  52. /* reduce: reduces number into specified interval (e.g. -PI, +PI)             */
  53. /*                                                                            */
  54. /******************************************************************************/
  55.  
  56. double reduce(value,rangeMin,rangeMax)
  57.  
  58. double value, rangeMin, rangeMax;
  59.  
  60. {
  61.     double range, rangeFrac, fullRanges, retval;
  62.  
  63.     range     = rangeMax - rangeMin;
  64.     rangeFrac = (rangeMax - value) / range;
  65.  
  66.     modf(rangeFrac,&fullRanges);
  67.  
  68.     retval = value + fullRanges * range;
  69.  
  70.     if (retval > rangeMax)
  71.         retval -= range;
  72.  
  73.     return(retval);
  74. }
  75.  
  76. /******************************************************************************/
  77. /*                                                                            */
  78. /* End of function block satmath.c                                            */
  79. /*                                                                            */
  80. /******************************************************************************/
  81.